<?php
/**
 * Created by PhpStorm.
 * User: nightelf
 * Date: 2020/1/9
 * Time: 14:32
 */

namespace App\Http\Model;


use Illuminate\Support\Facades\DB;

class PermissionModel
{
    const TABLE = 'permission';
    const MENU = 1;
    const BUTTON = 2;
    const RESOURCE = 3;

    /**
     * 权限列表
     * @param array $data
     * @return mixed
     */
    public function lists(array $data)
    {
        return DB::table(self::TABLE)
            ->where(function ($query) use ($data) {
                $type = [self::MENU, self::BUTTON];
                $query->where('status', 1)->whereIn('type', $type);
                if (!empty($data['isProject'])) {
                    $query->where('isProject', $data['isProject']);
                }
            })
            ->get()->toArray();
    }

    public function info(array $data)
    {
        $result = DB::table(self::TABLE)->where($data)->first();
        return empty($result)?[]:get_object_vars($result);
    }
}